//
//  StatisticsMemberViewController.m
//  YunDongAdmin
//
//  Created by lqq on 2018/9/19.
//  Copyright © 2018年 cloudfighting.com. All rights reserved.
//

#import "StatisticsMemberViewController.h"
#import "StatisticsMemberCell.h"
#import "I_Statistics.h"
@interface StatisticsMemberViewController ()
@property (nonatomic, assign) StatisticsMemberType type;
@property (nonatomic, assign) BOOL isCheckAll;//
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation StatisticsMemberViewController
#pragma mark Class Method
+ (instancetype)controllerWithStatisticsMemberType:(StatisticsMemberType)type isCheckAll:(BOOL)isCheckoutAll
{
    StatisticsMemberViewController *vc = [[StatisticsMemberViewController alloc] init];
    vc.type = type;
    vc.isCheckAll = isCheckoutAll;
    return vc;
}

#pragma mark Life Circle
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    switch (_type) {
        case StatisticsMemberType_TodayPlan:
        {
            self.title = @"排课计划";
        }
            break;
        case StatisticsMemberType_TodayRecord:
        {
            self.title = @"到店训练";
        }
            break;
        case StatisticsMemberType_TodayAddMember:
        {
            self.title = @"新增会员";
        }
            break;
            
            
        default:
            break;
    }
    
    [self configUI];
    [self requestStatisticsMemberList];
}

#pragma mark UI
- (void)configUI
{
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([StatisticsMemberCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([StatisticsMemberCell class])];
}

#pragma mark NET
- (void)requestStatisticsMemberList
{
    [self.view showLoading];
    WeakSelf(self);
    [I_Statistics requestGymOverviewForMemberIsCheckAll:_isCheckAll statisticsMemberType:_type date:[NSDate date] success:^(NSMutableArray *list) {
        [weakself.view hideStatusView];
        weakself.dataSource = list;
        if (list.count == 0) {
            [weakself.view showEmptyingView];
        }
        [weakself.tableView reloadData];
    } failure:^(NSError *error) {
        [weakself.view showError:error refreshBlock:^{
            [weakself requestStatisticsMemberList];
        }];
    }];
}


#pragma mark UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    StatisticsMemberCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([StatisticsMemberCell class])];
    cell.statisticsMember = _dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}


@end
